package com.yanqu.road.server.cmd.activity.dunhuangshiku;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.dunhuangshiku.DunHuangShiKuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.dunhuangshiku.DunHuangShiKuModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.Property;

/**
 * @Description
 * @Author cwq
 * @Data 2021/4/19 18:05
 */
@Cmd(code = GameProtocol.S_DUN_HUANG_SHI_KU_CREAT_TEAM_FROM_CROSS, desc = "敦煌石窟创建队伍 跨服返回区服 协议")
public class DunHuangShikuCreateTeamFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DunHuangShiKuProto.DunHuangShiKuCreateTeamRespMsg respMsg = DunHuangShiKuProto.DunHuangShiKuCreateTeamRespMsg.parseFrom(packet.getBytes());
        ret = respMsg.getRet();
        DunHuangShiKuModule dunHuangShiKuModule = player.getModule(DunHuangShiKuModule.class);
        Property property = dunHuangShiKuModule.createTeamProperty;
        if(dunHuangShiKuModule.createTeamProperty != null){
            // 恢复预扣除项
            player.getModule(PreReduceModule.class).restorePreReduce(dunHuangShiKuModule.createTeamProperty);
            dunHuangShiKuModule.createTeamProperty = null;
        }
        if(ret == 0){
            if(!respMsg.getIsFirstCreate()){
                // 扣元宝
                CurrencyModule module = player.getModule(CurrencyModule.class);
                module.removeCurrency(property, eLogMoneyType.DunHuangShiKu, eLogMoneyType.DunHuangShiKuCreatTeamCost);
            }
        }
        player.sendPacket(ClientProtocol.U_DUN_HUANG_SHI_KU_CREAT_TEAM, respMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {
    }
}
